package com.nsgf.library.data.bean;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

import android.content.Context;
import android.content.Intent;

import com.nsgf.library.base.BaseApplication;
import com.nsgf.library.data.api.APIs;
import com.nsgf.library.ui.page.LoginActivity;
import com.nsgf.library.utils.SPUtil;
import com.nsgf.library.utils.SpKey;
import com.nsgf.library.utils.StringUtil;

import java.util.List;

public class UserInfo {

    private static UserInfo instance = new UserInfo();
    private Context context;

    public UserInfo() {
        this.context = BaseApplication.getInstance();
    }

    public String getTokenName() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "tokenName", "tokenName", context);
    }

    public void setTokenName(String tokenName) {
        SPUtil.put(SpKey.KEY_USER_INFO, "tokenName", tokenName, context);
    }

    public String getName() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "name", "", context);
    }

    public void setName(String name) {
        SPUtil.put(SpKey.KEY_USER_INFO, "name", name, context);
    }


    public String getPhone() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "phone", "", context);
    }

    public void setPhone(String phone) {
        SPUtil.put(SpKey.KEY_USER_INFO, "phone", phone, context);
    }


    public String getPosition() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "position", "", context);
    }

    public void setPosition(String position) {
        SPUtil.put(SpKey.KEY_USER_INFO, "position", position, context);
    }


    public String getDeptName() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "deptName", "", context);
    }

    public void setDeptName(String deptName) {
        SPUtil.put(SpKey.KEY_USER_INFO, "deptName", deptName, context);
    }


    public String getActivityType() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "ActivityType", "", context);
    }

    public void setActivityType(String name) {
        SPUtil.put(SpKey.KEY_USER_INFO, "ActivityType", name, context);
    }


    public void setId(String id) {
        SPUtil.put(SpKey.KEY_USER_INFO, "id", id, context);
    }

    public String getId() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "id", "", context);
    }

    public String getTokenValue() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "tokenValue", "", context);
    }

    public String getLat() {
        return SPUtil.get(SpKey.KEY_LATITUDE, "0.0", context);
    }

    public String getLong() {
        return SPUtil.get(SpKey.KEY_LONGITUDE, "0.0", context);
    }

    public void setTokenValue(String tokenValue) {
        SPUtil.put(SpKey.KEY_USER_INFO, "tokenValue", tokenValue, context);
    }

    public void setProjectCode(String projectCode) {
        SPUtil.put(SpKey.KEY_USER_INFO, "projectCode", projectCode, context);
    }

    public void setProjectLat(String lat) {
        SPUtil.put(SpKey.KEY_USER_INFO, "lat", lat, context);
    }

    public void setProjectLon(String lon) {
        SPUtil.put(SpKey.KEY_USER_INFO, "lon", lon, context);
    }


    public String getProjectCode() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "projectCode", "", context);
    }

    public String getProjectLon() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "lon", "0.0", context);
    }

    public String getProjectLat() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "lat", "0.0", context);
    }

    public void setAppLogo(String appLogo) {
        SPUtil.put(SpKey.KEY_USER_INFO, "appLogo", appLogo, context);
    }

    public String getAppLog() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "appLogo", "", context);
    }

    public String getProjectName() {
        return SPUtil.get(SpKey.KEY_USER_INFO, "projectName", "", context);
    }

    public void setProjectName(String projectName) {
        SPUtil.put(SpKey.KEY_USER_INFO, "projectName", projectName, context);
    }

    public static UserInfo getInstance() {
        if (instance == null) {
            synchronized (UserInfo.class) {
                if (instance == null) instance = new UserInfo();
            }
        }
        return instance;
    }

    public void clearUserInfo() {
        SPUtil.clear(SpKey.KEY_USER_INFO, context);
        context.startActivity(new Intent()
                .setFlags(FLAG_ACTIVITY_NEW_TASK).setClass(context, LoginActivity.class));
    }

    private int userId;
    private UserBean user;
    private TokenInfoBean tokenInfo;

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public UserBean getUser() {
        return user;
    }

    public void setUser(UserBean user) {
        this.user = user;
    }

    public TokenInfoBean getTokenInfo() {
        return tokenInfo;
    }

    public void setTokenInfo(TokenInfoBean tokenInfo) {
        this.tokenInfo = tokenInfo;
    }

    public static class UserBean {
        private int id;
        private String username;
        private String password;
        private String salt;
        private String position;
        private String technicalGrade;
        private String jobGrade;
        private String sex;
        private String sexDesc;
        private String phone;
        private int status;
        private int userType;
        private String createTime;
        private String loginTime;
        private String loginIp;
        private int loginCount;
        private int isDel;
        private int roleId;
        private String roleName;
        private boolean singleProject;
        private String deptName;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public String getSalt() {
            return salt;
        }

        public void setSalt(String salt) {
            this.salt = salt;
        }

        public String getPosition() {
            return position;
        }

        public void setPosition(String position) {
            this.position = position;
        }

        public String getTechnicalGrade() {
            return technicalGrade;
        }

        public void setTechnicalGrade(String technicalGrade) {
            this.technicalGrade = technicalGrade;
        }

        public String getJobGrade() {
            return jobGrade;
        }

        public void setJobGrade(String jobGrade) {
            this.jobGrade = jobGrade;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }

        public String getSexDesc() {
            return sexDesc;
        }

        public void setSexDesc(String sexDesc) {
            this.sexDesc = sexDesc;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public int getUserType() {
            return userType;
        }

        public void setUserType(int userType) {
            this.userType = userType;
        }

        public String getCreateTime() {
            return createTime;
        }

        public void setCreateTime(String createTime) {
            this.createTime = createTime;
        }

        public String getLoginTime() {
            return loginTime;
        }

        public void setLoginTime(String loginTime) {
            this.loginTime = loginTime;
        }

        public String getLoginIp() {
            return loginIp;
        }

        public void setLoginIp(String loginIp) {
            this.loginIp = loginIp;
        }

        public int getLoginCount() {
            return loginCount;
        }

        public void setLoginCount(int loginCount) {
            this.loginCount = loginCount;
        }

        public int getIsDel() {
            return isDel;
        }

        public void setIsDel(int isDel) {
            this.isDel = isDel;
        }

        public int getRoleId() {
            return roleId;
        }

        public void setRoleId(int roleId) {
            this.roleId = roleId;
        }

        public String getRoleName() {
            return roleName;
        }

        public void setRoleName(String roleName) {
            this.roleName = roleName;
        }

        public boolean isSingleProject() {
            return singleProject;
        }

        public void setSingleProject(boolean singleProject) {
            this.singleProject = singleProject;
        }

        public String getDeptName() {
            return StringUtil.isEmpty(deptName) ? "" : deptName;
        }

        public void setDeptName(String deptName) {
            this.deptName = deptName;
        }
    }

    public static class TokenInfoBean {

        private String tokenName;
        private String tokenValue;
        private boolean isLogin;
        private String loginId;
        private String loginType;
        private int tokenTimeout;
        private int sessionTimeout;
        private int tokenSessionTimeout;
        private int tokenActivityTimeout;
        private String loginDevice;
        private Object tag;

        public String getTokenName() {
            return tokenName;
        }

        public void setTokenName(String tokenName) {
            this.tokenName = tokenName;
        }

        public String getTokenValue() {
            return tokenValue;
        }

        public void setTokenValue(String tokenValue) {
            this.tokenValue = tokenValue;
        }

        public boolean isIsLogin() {
            return isLogin;
        }

        public void setIsLogin(boolean isLogin) {
            this.isLogin = isLogin;
        }

        public String getLoginId() {
            return loginId;
        }

        public void setLoginId(String loginId) {
            this.loginId = loginId;
        }

        public String getLoginType() {
            return loginType;
        }

        public void setLoginType(String loginType) {
            this.loginType = loginType;
        }

        public int getTokenTimeout() {
            return tokenTimeout;
        }

        public void setTokenTimeout(int tokenTimeout) {
            this.tokenTimeout = tokenTimeout;
        }

        public int getSessionTimeout() {
            return sessionTimeout;
        }

        public void setSessionTimeout(int sessionTimeout) {
            this.sessionTimeout = sessionTimeout;
        }

        public int getTokenSessionTimeout() {
            return tokenSessionTimeout;
        }

        public void setTokenSessionTimeout(int tokenSessionTimeout) {
            this.tokenSessionTimeout = tokenSessionTimeout;
        }

        public int getTokenActivityTimeout() {
            return tokenActivityTimeout;
        }

        public void setTokenActivityTimeout(int tokenActivityTimeout) {
            this.tokenActivityTimeout = tokenActivityTimeout;
        }

        public String getLoginDevice() {
            return loginDevice;
        }

        public void setLoginDevice(String loginDevice) {
            this.loginDevice = loginDevice;
        }

        public Object getTag() {
            return tag;
        }

        public void setTag(Object tag) {
            this.tag = tag;
        }
    }

    private AdminBean admin;
    private AppCfgBean appCfg;
    private List<MenuListBean> menuList;
    private List<?> perList;
    private List<ProjectListBean> projectList;

    public AdminBean getAdmin() {
        return admin;
    }

    public void setAdmin(AdminBean admin) {
        this.admin = admin;
    }

    public AppCfgBean getAppCfg() {
        return appCfg;
    }

    public void setAppCfg(AppCfgBean appCfg) {
        this.appCfg = appCfg;
    }

    public List<MenuListBean> getMenuList() {
        return menuList;
    }

    public void setMenuList(List<MenuListBean> menuList) {
        this.menuList = menuList;
    }

    public List<?> getPerList() {
        return perList;
    }

    public void setPerList(List<?> perList) {
        this.perList = perList;
    }

    public List<ProjectListBean> getProjectList() {
        return projectList;
    }

    public void setProjectList(List<ProjectListBean> projectList) {
        this.projectList = projectList;
    }

    public static class AdminBean {
        /**
         * id : 1000017
         * username : app
         * password :
         * salt :
         * position : null
         * technicalGrade : null
         * jobGrade : null
         * sex : people.sex.1
         * sexDesc : 男
         * phone :
         * status : 1
         * userType : 0
         * createTime : 2024-09-13 09:43:01
         * loginTime : 2024-09-13 10:01:56
         * loginIp : 40.0.1.74
         * loginCount : 2
         * isDel : 1
         * roleId : 4
         * roleName : 普通账号
         */

        private int id;
        private String username;
        private String password;
        private String salt;
        private Object position;
        private Object technicalGrade;
        private Object jobGrade;
        private String sex;
        private String sexDesc;
        private String phone;
        private int status;
        private int userType;
        private String createTime;
        private String loginTime;
        private String loginIp;
        private int loginCount;
        private int isDel;
        private int roleId;
        private String roleName;
        private boolean singleProject;
        private String deptName;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public String getSalt() {
            return salt;
        }

        public void setSalt(String salt) {
            this.salt = salt;
        }

        public Object getPosition() {
            return position;
        }

        public void setPosition(Object position) {
            this.position = position;
        }

        public Object getTechnicalGrade() {
            return technicalGrade;
        }

        public void setTechnicalGrade(Object technicalGrade) {
            this.technicalGrade = technicalGrade;
        }

        public Object getJobGrade() {
            return jobGrade;
        }

        public void setJobGrade(Object jobGrade) {
            this.jobGrade = jobGrade;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }

        public String getSexDesc() {
            return sexDesc;
        }

        public void setSexDesc(String sexDesc) {
            this.sexDesc = sexDesc;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public int getUserType() {
            return userType;
        }

        public void setUserType(int userType) {
            this.userType = userType;
        }

        public String getCreateTime() {
            return createTime;
        }

        public void setCreateTime(String createTime) {
            this.createTime = createTime;
        }

        public String getLoginTime() {
            return loginTime;
        }

        public void setLoginTime(String loginTime) {
            this.loginTime = loginTime;
        }

        public String getLoginIp() {
            return loginIp;
        }

        public void setLoginIp(String loginIp) {
            this.loginIp = loginIp;
        }

        public int getLoginCount() {
            return loginCount;
        }

        public void setLoginCount(int loginCount) {
            this.loginCount = loginCount;
        }

        public int getIsDel() {
            return isDel;
        }

        public void setIsDel(int isDel) {
            this.isDel = isDel;
        }

        public int getRoleId() {
            return roleId;
        }

        public void setRoleId(int roleId) {
            this.roleId = roleId;
        }

        public String getRoleName() {
            return roleName;
        }

        public void setRoleName(String roleName) {
            this.roleName = roleName;
        }

        public boolean isSingleProject() {
            return singleProject;
        }

        public void setSingleProject(boolean singleProject) {
            this.singleProject = singleProject;
        }

        public String getDeptName() {
            return deptName;
        }

        public void setDeptName(String deptName) {
            this.deptName = deptName;
        }
    }

    public static class AppCfgBean {
        /**
         * appName : Sa-Sso-Pro 后台
         * appLogo : http://file.dev33.cn/ssp/ssp-logo-480.png
         * appVersion : v1.6.0
         * appIntro : Sa-Sso-Pro 后台管理
         * isDynamicInfo : false
         * appUpdateTime : 2023-1-13
         */

        private String appName;
        private String appLogo;
        private String appVersion;
        private String appIntro;
        private String isDynamicInfo;
        private String appUpdateTime;

        public String getAppName() {
            return appName;
        }

        public void setAppName(String appName) {
            this.appName = appName;
        }

        public String getAppLogo() {
            return appLogo;
        }

        public void setAppLogo(String appLogo) {
            this.appLogo = appLogo;
        }

        public String getAppVersion() {
            return appVersion;
        }

        public void setAppVersion(String appVersion) {
            this.appVersion = appVersion;
        }

        public String getAppIntro() {
            return appIntro;
        }

        public void setAppIntro(String appIntro) {
            this.appIntro = appIntro;
        }

        public String getIsDynamicInfo() {
            return isDynamicInfo;
        }

        public void setIsDynamicInfo(String isDynamicInfo) {
            this.isDynamicInfo = isDynamicInfo;
        }

        public String getAppUpdateTime() {
            return appUpdateTime;
        }

        public void setAppUpdateTime(String appUpdateTime) {
            this.appUpdateTime = appUpdateTime;
        }
    }

    public static class MenuListBean {
        /**
         * aid : 1807957874682347521
         * id : shuiliduixiang
         * title : 水利对象
         * icon :
         * info :
         * type : dir
         * path :
         * componentPath :
         * url :
         * isBlank : false
         * isShow : yes
         * auth : true
         * parentId : shuiliziyuanpeizhi
         * sort : 1
         * createTime : 2024-07-02 10:02:02
         * updateTime : 2024-07-02 10:02:46
         */

        private long aid;
        private String id;
        private String title;
        private String icon;
        private String info;
        private String type;
        private String path;
        private String componentPath;
        private String url;
        private boolean isBlank;
        private String isShow;
        private boolean auth;
        private String parentId;
        private int sort;
        private String createTime;
        private String updateTime;

        public long getAid() {
            return aid;
        }

        public void setAid(long aid) {
            this.aid = aid;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getIcon() {
            return icon;
        }

        public void setIcon(String icon) {
            this.icon = icon;
        }

        public String getInfo() {
            return info;
        }

        public void setInfo(String info) {
            this.info = info;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getPath() {
            return path;
        }

        public void setPath(String path) {
            this.path = path;
        }

        public String getComponentPath() {
            return componentPath;
        }

        public void setComponentPath(String componentPath) {
            this.componentPath = componentPath;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public boolean isIsBlank() {
            return isBlank;
        }

        public void setIsBlank(boolean isBlank) {
            this.isBlank = isBlank;
        }

        public String getIsShow() {
            return isShow;
        }

        public void setIsShow(String isShow) {
            this.isShow = isShow;
        }

        public boolean isAuth() {
            return auth;
        }

        public void setAuth(boolean auth) {
            this.auth = auth;
        }

        public String getParentId() {
            return parentId;
        }

        public void setParentId(String parentId) {
            this.parentId = parentId;
        }

        public int getSort() {
            return sort;
        }

        public void setSort(int sort) {
            this.sort = sort;
        }

        public String getCreateTime() {
            return createTime;
        }

        public void setCreateTime(String createTime) {
            this.createTime = createTime;
        }

        public String getUpdateTime() {
            return updateTime;
        }

        public void setUpdateTime(String updateTime) {
            this.updateTime = updateTime;
        }
    }

    public static class ProjectListBean {
        /**
         * id : 627B7001
         * projectCode : 627B7001
         * facilityCode : 627B7001
         * projectName : 栖霞水库1
         * instantId : 2424020096255
         * projectTitle : 栖霞水库运行管理矩阵平台
         * projectId : 4
         * versions : 6.0
         * waterSite : 111
         * rainSite : 1234
         * upRiver : jzhd1817812440088449024,jzhd1817813164910317568,jzhd1818198705044590592
         * downRiver : jzhd1824277036466835456,jzhd1824374512473477120,jzhd1825448333053923328
         * status : 1
         * projectType : water.obj.type.2
         * projectTypeDesc : 水库
         * createBy : 1111
         * createTime : null
         * upRivers : null
         * downRivers : null
         * areaCode : null
         */

        private String id;
        private String projectCode;
        private String facilityCode;
        private String projectName;
        private String instantId;
        private String projectTitle;
        private String projectId;
        private String versions;
        private String waterSite;
        private String rainSite;
        private String upRiver;
        private String downRiver;
        private int status;
        private String projectType;
        private String projectTypeDesc;
        private String createBy;
        private Object createTime;
        private Object upRivers;
        private Object downRivers;
        private Object areaCode;
        private String area;
        private String facilityName;
        private String location;
        private String pictureUrl;
        private int isExperiment;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getProjectCode() {
            return projectCode;
        }

        public void setProjectCode(String projectCode) {
            this.projectCode = projectCode;
        }

        public String getFacilityCode() {
            return StringUtil.isEmpty(facilityCode) ? "" : facilityCode;
        }

        public void setFacilityCode(String facilityCode) {
            this.facilityCode = facilityCode;
        }

        public String getProjectName() {
            return projectName;
        }

        public void setProjectName(String projectName) {
            this.projectName = projectName;
        }

        public String getInstantId() {
            return instantId;
        }

        public void setInstantId(String instantId) {
            this.instantId = instantId;
        }

        public String getProjectTitle() {
            return projectTitle;
        }

        public void setProjectTitle(String projectTitle) {
            this.projectTitle = projectTitle;
        }

        public String getProjectId() {
            return projectId;
        }

        public void setProjectId(String projectId) {
            this.projectId = projectId;
        }

        public String getVersions() {
            return versions;
        }

        public void setVersions(String versions) {
            this.versions = versions;
        }

        public String getWaterSite() {
            return waterSite;
        }

        public void setWaterSite(String waterSite) {
            this.waterSite = waterSite;
        }

        public String getRainSite() {
            return rainSite;
        }

        public void setRainSite(String rainSite) {
            this.rainSite = rainSite;
        }

        public String getUpRiver() {
            return upRiver;
        }

        public void setUpRiver(String upRiver) {
            this.upRiver = upRiver;
        }

        public String getDownRiver() {
            return downRiver;
        }

        public void setDownRiver(String downRiver) {
            this.downRiver = downRiver;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getProjectType() {
            return projectType;
        }

        public void setProjectType(String projectType) {
            this.projectType = projectType;
        }

        public String getProjectTypeDesc() {
            return projectTypeDesc;
        }

        public void setProjectTypeDesc(String projectTypeDesc) {
            this.projectTypeDesc = projectTypeDesc;
        }

        public String getCreateBy() {
            return createBy;
        }

        public void setCreateBy(String createBy) {
            this.createBy = createBy;
        }

        public Object getCreateTime() {
            return createTime;
        }

        public void setCreateTime(Object createTime) {
            this.createTime = createTime;
        }

        public Object getUpRivers() {
            return upRivers;
        }

        public void setUpRivers(Object upRivers) {
            this.upRivers = upRivers;
        }

        public Object getDownRivers() {
            return downRivers;
        }

        public void setDownRivers(Object downRivers) {
            this.downRivers = downRivers;
        }

        public Object getAreaCode() {
            return areaCode;
        }

        public void setAreaCode(Object areaCode) {
            this.areaCode = areaCode;
        }

        public String getArea() {
            return StringUtil.isEmpty(area) ? "" : area;
        }

        public void setArea(String area) {
            this.area = area;
        }

        public String getFacilityName() {
            return facilityName;
        }

        public void setFacilityName(String facilityName) {
            this.facilityName = facilityName;
        }

        public String getLocation() {
            return StringUtil.isEmpty(location) ? "" : location;
        }

        public void setLocation(String location) {
            this.location = location;
        }

        public String getPictureUrl() {
            return StringUtil.isEmpty(pictureUrl) ? "" : pictureUrl;
        }

        public String getPictureUrlSrc() {

            if (StringUtil.isEmpty(getPictureUrl()))
                return "";
            else {
                String[] src = getPictureUrl().split(",");
                if (src.length > 0) {
                    return APIs.BASE_URL_IMG + src[0];
                }
                return "";
            }

        }

        public void setPictureUrl(String pictureUrl) {
            this.pictureUrl = pictureUrl;
        }

        public int getIsExperiment() {
            return isExperiment;
        }

        public void setIsExperiment(int isExperiment) {
            this.isExperiment = isExperiment;
        }
    }
}
